Component({
  /**
   * 组件的属性列表
   */
  props: {
    selector: 'skeletons',
    background: '#FFF',
    skt_animation: 'shine',
    isNodes: false,
    isComplete: false
  },
  didUpdate(newVal, oldVal) {
    if (this.props.isNodes) {
      this.props.onNodes({ isNodes: false })
      this.rectList = this.getSelector(`.${this.selector} >>> .${this.selector}-rect`);
      this.circleList = this.getSelector(`.${this.selector} >>> .${this.selector}-circle`);
      //捕获节点后关闭加载动效
      this.setData({
        isLoading: false
      }, () => {
        ['rectList', 'circleList'].forEach((name) => {
          this.drawNodes(name, this[name]);
        })
      })
    }
    if (this.props.isComplete) {
      setTimeout(() => {
        console.log('隐藏关闭组件');
        this.setData({
          visible: false
        }, () => {
          setTimeout(() => {
            this.setData({
              visible: false
            })
          }, 1000)
        })
      }, 1000)
    }
  },
  data: {
    visible: true, //组件展示
    rectList: [],
    circleList: [],
    isLoading: true,
    systemInfo: {
      height: 0,
      width: 0,
      top: 0,
      left: 0
    }
  },
  onInit() {
    this.setData({
      'systemInfo.width': my.getSystemInfoSync().windowWidth,
      'systemInfo.height': my.getSystemInfoSync().windowHeight
    })
    this.selector = this.props.selector
    this.getSelector(`.${this.props.selector}`).boundingClientRect().exec((res) => {
      if (res[0][0]) {
        this.setData({
          'systemInfo.top': res[0][0].top,
          'systemInfo.left': res[0][0].left
        })
      }
    })
  },
  methods: {
    getSelector: (name) => my.createSelectorQuery().selectAll(name),
    drawNodes(name, selector) {
      console.log(selector)
      selector.boundingClientRect().exec((res) => {
        if (res[0]) {
          this.setData({
            [name]: res[0].filter(todo => todo.top <= this.data.systemInfo.height)
          })
        }
      })
    }
  }
})
